VERSION 2.00
Begin Form frmTInfo 
   BackColor       =   &H00C0C0C0&
   BorderStyle     =   1  'Fixed Single
   Caption         =   "frmTInfo"
   ClientHeight    =   4305
   ClientLeft      =   135
   ClientTop       =   1095
   ClientWidth     =   8880
   Height          =   4710
   Left            =   75
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   4305
   ScaleWidth      =   8880
   Top             =   750
   Width           =   9000
   Begin SSPanel pnlMain 
      BackColor       =   &H00C0C0C0&
      Font3D          =   0  'None
      ForeColor       =   &H00000000&
      Height          =   4290
      Left            =   30
      TabIndex        =   7
      Top             =   30
      Width           =   8835
      Begin CommandButton cmdCancel 
         BackColor       =   &H00C0C0C0&
         Cancel          =   -1  'True
         Caption         =   "Cancel"
         Height          =   375
         Left            =   7320
         TabIndex        =   5
         Tag             =   "Cancel"
         Top             =   660
         Width           =   1095
      End
      Begin CommandButton cmdOK 
         BackColor       =   &H00C0C0C0&
         Caption         =   "OK"
         Default         =   -1  'True
         Height          =   375
         Left            =   7320
         TabIndex        =   4
         Top             =   195
         Width           =   1095
      End
      Begin SSPanel pnlGrid 
         BackColor       =   &H00C0C0C0&
         BevelOuter      =   1  'Inset
         Font3D          =   0  'None
         ForeColor       =   &H00000000&
         Height          =   2625
         Left            =   135
         TabIndex        =   11
         Top             =   1545
         Width           =   8610
         Begin SSCommand cmdEdit 
            Font3D          =   0  'None
            Height          =   280
            Index           =   0
            Left            =   30
            Picture         =   TASKINFO.FRX:0000
            RoundedCorners  =   0   'False
            TabIndex        =   12
            TabStop         =   0   'False
            Tag             =   "Cross"
            Top             =   30
            Visible         =   0   'False
            Width           =   280
         End
         Begin SSCommand cmdEdit 
            Font3D          =   0  'None
            Height          =   280
            Index           =   1
            Left            =   315
            Picture         =   TASKINFO.FRX:05A2
            RoundedCorners  =   0   'False
            TabIndex        =   13
            TabStop         =   0   'False
            Tag             =   "Check"
            Top             =   30
            Visible         =   0   'False
            Width           =   280
         End
         Begin TextBox txtEdit 
            Enabled         =   0   'False
            Height          =   285
            Left            =   615
            TabIndex        =   14
            TabStop         =   0   'False
            Tag             =   "Edit"
            Top             =   30
            Width           =   7950
         End
         Begin Grid Grid 
            BorderStyle     =   0  'None
            Cols            =   9
            FixedCols       =   5
            FontBold        =   0   'False
            FontItalic      =   0   'False
            FontName        =   "MS Sans Serif"
            FontSize        =   8.25
            FontStrikethru  =   0   'False
            FontUnderline   =   0   'False
            ForeColor       =   &H00000000&
            Height          =   2280
            HighLight       =   0   'False
            Left            =   15
            TabIndex        =   3
            Tag             =   "Homer"
            Top             =   330
            Width           =   8520
         End
         Begin Shape shpRect 
            Height          =   285
            Left            =   15
            Top             =   30
            Width           =   600
         End
      End
      Begin SSPanel pnlName 
         Alignment       =   2  'Left Justify - BOTTOM
         BackColor       =   &H00C0C0C0&
         BevelOuter      =   1  'Inset
         Font3D          =   0  'None
         FontBold        =   0   'False
         FontItalic      =   0   'False
         FontName        =   "MS Sans Serif"
         FontSize        =   8.25
         FontStrikethru  =   0   'False
         FontUnderline   =   0   'False
         ForeColor       =   &H00000000&
         Height          =   330
         Left            =   2160
         TabIndex        =   10
         Top             =   195
         Width           =   3795
      End
      Begin SSPanel pnlDateRange 
         Alignment       =   1  'Left Justify - MIDDLE
         BackColor       =   &H00C0C0C0&
         BevelOuter      =   1  'Inset
         Font3D          =   0  'None
         FontBold        =   0   'False
         FontItalic      =   0   'False
         FontName        =   "MS Sans Serif"
         FontSize        =   8.25
         FontStrikethru  =   0   'False
         FontUnderline   =   0   'False
         ForeColor       =   &H00000000&
         Height          =   330
         Left            =   2160
         TabIndex        =   9
         Top             =   600
         Width           =   3795
      End
      Begin SSPanel pnlAsOf 
         Alignment       =   1  'Left Justify - MIDDLE
         AutoSize        =   3  'AutoSize Child To Panel
         BackColor       =   &H00C0C0C0&
         BevelOuter      =   1  'Inset
         Font3D          =   0  'None
         FontBold        =   0   'False
         FontItalic      =   0   'False
         FontName        =   "MS Sans Serif"
         FontSize        =   8.25
         FontStrikethru  =   0   'False
         FontUnderline   =   0   'False
         ForeColor       =   &H00000000&
         Height          =   360
         Left            =   2160
         TabIndex        =   8
         Top             =   1005
         Width           =   2925
         Begin TextBox txtAsOf 
            FontBold        =   0   'False
            FontItalic      =   0   'False
            FontName        =   "MS Sans Serif"
            FontSize        =   8.25
            FontStrikethru  =   0   'False
            FontUnderline   =   0   'False
            Height          =   330
            Left            =   15
            TabIndex        =   2
            Tag             =   "AsOf"
            Top             =   15
            Width           =   2895
         End
      End
      Begin Label lblName 
         BackColor       =   &H00C0C0C0&
         Caption         =   "Resource Name:"
         Height          =   240
         Left            =   555
         TabIndex        =   0
         Top             =   240
         Width           =   1530
      End
      Begin Label lblDateRange 
         BackColor       =   &H00C0C0C0&
         Caption         =   "Date Range:"
         Height          =   240
         Left            =   885
         TabIndex        =   6
         Top             =   645
         Width           =   1200
      End
      Begin Label lblAsOf 
         BackColor       =   &H00C0C0C0&
         Caption         =   "&Update As Of:"
         Height          =   240
         Left            =   765
         TabIndex        =   1
         Top             =   1050
         Width           =   1320
      End
   End
End
Option Explicit

' form constants
Const CHECK = 1
Const CROSS = 0
Const M_EDIT = True
Const M_DEFAULT = False

' Undo buffer for editing
Dim mUndoBuf As utUndo   'type declared in gridfunc.bas

' Default button properties flag
Dim mbDefButt As Integer

' Grid edit mode flag - True if edit mode, False if default mode
Dim mbEditMode As Integer

' Invalid entry in AsOf box
Dim mbInvalidAsOf As Integer

Sub CellEdit (nAction As Integer)

Dim nNewRow As Integer
Dim nNewCol As Integer

   On Error GoTo CellEditError

   Select Case nAction
      Case 0   ' cancel the edit (CROSS)
         Grid.Row = mUndoBuf.nRow
         Grid.Col = mUndoBuf.nCol
         txtEdit.Text = mUndoBuf.sUndo
         ToggleEditMode M_DEFAULT   ' Turn off editing
         Grid.SetFocus
      Case 1   ' accept the edit (CHECK)
         nNewCol = Grid.Col                     ' Save column.
         nNewRow = Grid.Row                     ' Save row.
         If TypeOf ActiveControl Is Grid Then      ' User selected another cell
            Grid.Col = mUndoBuf.nCol               ' Move back to edited cell.
            Grid.Row = mUndoBuf.nRow               '       "       "
         End If

         Select Case Grid.Col
            Case ADDWORK, ETC
               If Asc(Right$(Grid.Text, 1)) < 65 Then    ' If no work unit, then
                  Grid.Text = Grid.Text & gsDefWorkUnit  '    add default work unit.
               End If
            Case START
               If InStr(Grid.Text, gsTimeSep) <> 0 Then   ' User included time with date.
                  txtEdit.Text = DateValue(txtEdit.Text) + TimeValue(txtEdit.Text)
               Else
                  txtEdit.Text = DateValue(txtEdit.Text) + gdtDefStartTime
               End If
            Case FINISH
               If InStr(Grid.Text, gsTimeSep) <> 0 Then   ' User included time with date.
                  Grid.Text = DateValue(Grid.Text) + TimeValue(Grid.Text)
               Else
                  Grid.Text = DateValue(Grid.Text) + gdtDefFinishTime
               End If
         End Select


         If Not CheckEdit() Then                   ' If not a valid edit, then
            txtEdit.SelStart = 0
            txtEdit.SelLength = 32000  ' Highlight invalid entry
            txtEdit.SetFocus
         Else
            MarkCellDirty Grid.Col, Grid.Row, True
            ToggleEditMode M_DEFAULT
            If TypeOf ActiveControl Is Grid Then
               Grid.Col = nNewCol                  ' Move back to new cell.
               Grid.Row = nNewRow                  '       "         "
               Grid.SetFocus
            End If
         End If

   End Select

Exit Sub

CellEditError:
   Select Case Err
      Case 5           ' Illegal function call
         Beep
         MsgBox MB_BAD_DATE_FORMAT, MB_ICONEXCLAMATION, MB_TIMESHEET
         txtEdit.SelStart = 0
         txtEdit.SelLength = 32000
         txtEdit.SetFocus
      Case Else
         Beep
         CellEdit CROSS
   End Select
   Exit Sub

End Sub

Sub cmdCancel_Click ()

   Dim rtn%, hWnd%


   'Hide the task info form
   Me.Hide
   
   ' Show the Options form and move it to the top of the window z-order.
   frmOptions.Show
   frmOptions.cmdCancel.SetFocus
   hWnd% = frmOptions.hWnd
   If Not BringToTop(hWnd%) Then TerminateApplication

End Sub

Sub cmdCancel_GotFocus ()
   frmTInfo.Tag = "form"
End Sub

Sub cmdEdit_Click (Index As Integer)
' Either the Cross or the Check was pressed.

   Select Case Index
      Case CHECK                    ' Accept edit
         CellEdit CHECK
      Case CROSS                    ' Cancel edit
         CellEdit CROSS
   End Select

End Sub

Sub cmdOK_Click ()
   
   Dim sAsOf As String
   Dim dtAsOf As Variant, dtAsOfTime As Variant

   On Error GoTo cmdOKError

   If ActiveControl.Tag = "AsOf" Then
      txtAsOf_LostFocus
   End If

   If Not mbInvalidAsOf Then
      gdtAsOfDate = txtAsOf.Text
      dtAsOf = gdtAsOfDate
      DoResUpdate (dtAsOf)
      DisplayTInfoForm
   End If

Exit Sub

cmdOKError:
   Beep
   If gbDbg Then MsgBox "cmdOK_Click: Error:" & Err & ", " & Error$, MB_ICONEXCLAMATION, MB_TIMESHEET
   Exit Sub
   
End Sub

Sub cmdOK_GotFocus ()
   frmTInfo.Tag = "form"
End Sub

Sub Form_GotFocus ()
   frmTInfo.Tag = "form"
End Sub

' This procedure is responsible for cosmetic tasks, such as the size and
'positioning of controls on the form, and the position of the form
'on the screen.
Sub Form_Load ()

   ' Size and position the main 3D panel.
   pnlMain.Top = 0
   pnlMain.Left = 0
   pnlMain.Width = frmTInfo.ScaleWidth
   pnlMain.Height = frmTInfo.ScaleHeight

   ' Size and position the controls on the 3D panel enclosing
   'the task assignments grid.
   shpRect.Top = 30
   shpRect.Left = 30
   cmdEdit(0).Top = 30    'cross
   cmdEdit(0).Left = 30
   cmdEdit(1).Top = 30    'check
   cmdEdit(1).Left = 310
   txtEdit.Top = 30
   txtEdit.Left = 590
   txtEdit.Width = pnlGrid.Width - 620
   Grid.Top = 310
   Grid.Left = 25
   Grid.Width = pnlGrid.Width - 60
   Grid.Height = pnlGrid.Height - 340
   
   ' Center the form on the screen.
   frmTInfo.Top = (Screen.Height - frmTInfo.Height) / 2
   frmTInfo.Left = (Screen.Width - frmTInfo.Width) / 2
   
   ' Initialize the grid control.
   InitializeGrid
   
   txtAsOf.Text = gdtTodaysDate
   
End Sub

Sub Grid_GotFocus ()


   ' indicate that the grid was the last control to have the focus
   frmTInfo.Tag = "grid"

   Grid_SelChange

End Sub

Sub Grid_KeyPress (KeyAscii As Integer)
   
   
      If CellIsEditable(-1, -1) Then
         ToggleEditMode M_EDIT         ' Go to edit mode.
         If KeyAscii > 31 Then
            Grid.Text = Chr(KeyAscii)     ' Enter text in grid.
            txtEdit.Text = Grid.Text      ' Same text goes in edit box.
         End If
         txtEdit.SetFocus              ' Set focus to edit box.
         txtEdit.SelStart = 2          ' Move insertion point to end of text.
      End If
   

End Sub

Sub Grid_SelChange ()
   
   If Not frmTInfo.Visible Then Exit Sub  ' grid may gpf if certain properties are altered while the form is hidden
   
   Grid.Row = Grid.SelStartRow
   Grid.Col = Grid.SelStartCol
   
   ' display grid text in the edit bar
   txtEdit.Text = Grid.Text


   If CellIsEditable(-1, -1) Then
      txtEdit.Enabled = True
   Else
      txtEdit.Enabled = False
   End If

End Sub

' Takes care of the actions associated with toggling between Edit and
'Default modes. bMode = M_EDIT : edit mode on; bMode = M_DEFAULT: default mode on.
Sub ToggleEditMode (bMode As Integer)

   If bMode Then  ' Edit mode

      ' cancel default ok/cancel behavior
      cmdOK.Default = False
      cmdCancel.Cancel = False

      ' show Cross and Check buttons
      cmdEdit(CHECK).Visible = True
      cmdEdit(CROSS).Visible = True

      ' load the Undo buffer
         mUndoBuf.sUndo = ActiveControl.Text
         mUndoBuf.nRow = Grid.Row
         mUndoBuf.nCol = Grid.Col

      ' set the edit mode flag
      mbEditMode = M_EDIT

   Else  ' Default mode

      ' enable default ok/cancel behavior
      cmdOK.Default = True
      cmdCancel.Cancel = True

      ' hide Cross and Check buttons
      cmdEdit(CHECK).Visible = False
      cmdEdit(CROSS).Visible = False

      ' clear the Undo buffer
      mUndoBuf.nTag = 0  'invalidates undo buffer

      ' clear the edit mode flag
      mbEditMode = M_DEFAULT

   End If

End Sub

Sub txtAsOf_GotFocus ()
   frmTInfo.Tag = "form"
End Sub

Sub txtAsOf_LostFocus ()

Dim X

   On Error GoTo AsOfError

   If ActiveControl.Tag <> "Cancel" Then
      X = DateValue(txtAsOf.Text) + TimeValue(txtAsOf.Text) 'generates an error if an invalid date is entered.
      mbInvalidAsOf = False
   End If
   Exit Sub

AsOfError:
   If Err = 5 Then
      Beep
      mbInvalidAsOf = True
      MsgBox MB_BAD_ASOF_DATE, MB_ICONEXCLAMATION, MB_TIMESHEET
      txtAsOf.SelStart = 0
      txtAsOf.SelLength = 32000
      txtAsOf.SetFocus
   End If
   Exit Sub

End Sub

Sub txtEdit_Change ()

   If mbEditMode Then            ' If in edit mode, then
      Grid.Text = txtEdit.Text   '    echo text to grid cell.
   End If

End Sub

Sub txtEdit_GotFocus ()
   
   Grid.SelStartRow = Grid.Row
   Grid.SelEndRow = Grid.Row
   Grid.SelStartCol = Grid.Col
   Grid.SelEndCol = Grid.Col
   Grid.HighLight = True
   If Not mbEditMode Then        ' If not in edit mode, then
      txtEdit.Text = Grid.Text   '    Put grid text in edit box.
      ToggleEditMode M_EDIT      '    Go to edit mode.
   End If

End Sub

Sub txtEdit_KeyPress (KeyAscii As Integer)
   

   Select Case KeyAscii
      Case 13  'Enter
         KeyAscii = 0
         Grid.SetFocus
         'cmdEdit_Click (CHECK)
      Case 27  'Esc
         KeyAscii = 0
         cmdEdit_Click (CROSS)
      Case Else
         
   End Select

End Sub

Sub txtEdit_LostFocus ()

Dim sTemp As String


   Grid.HighLight = False
   sTemp = ActiveControl.Tag
   If sTemp <> "Cross" And sTemp <> "Cancel" Then
      cmdEdit_Click CHECK
   End If

End Sub

